package com.xxx.io;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

/**
 * @author blijojo
 * @date 2021/7/12 13:17
 * 传统IO编程-客户端
 */
public class MyClient {
    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            new Client().start();
        }
    }

    static class Client extends Thread {
        @Override
        public void run() {
            try {
                Socket socket = new Socket("127.0.0.1", 8000);
                OutputStream outputStream = socket.getOutputStream();
                while (true) {
                    outputStream.write("测试".getBytes(StandardCharsets.UTF_8));
//                    outputStream.flush();
                    Thread.sleep(2000);
                }
            } catch (IOException | InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
